<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>margin上下折叠</title>
  </head>

  <style>
    /* 
    一.margin上下折叠
      1.1 div1和div2兄弟元素，只会呈现 margin-bottom: 20px;和margin-top: 20px;中数值大的
      1.2 解决办法：只写其中一个就好了
     */
    .div1 {
      width: 100px;
      height: 100px;
      background-color: pink;
      margin-bottom: 20px;
    }

    .div2 {
      width: 100px;
      height: 100px;
      background-color: red;
      margin-top: 20px;
    }
  </style>

  <body>
    <div class="div1"></div>
    <div class="div2"></div>
  </body>

</html>